package elsim.entities;

import static org.junit.Assert.*

import org.junit.Test

class PassengerAlgorithmsTest {
  @Test
  void isPointAlongTheWayUp() {
    Lift lift = new Lift(0)
    lift.position = 15
    lift.addPendingRequest(new Passenger("abc", 30))
    lift.direction = Direction.UP
    
    assertTrue(PassengerAlgorithms.isPointAlongTheWay(lift, 18))
    assertFalse(PassengerAlgorithms.isPointAlongTheWay(lift, 12))
  }
  
  @Test
  void isPointAlongTheWayDown() {
    Lift lift = new Lift(0)
    lift.position = 25
    lift.addPendingRequest(new Passenger("abc", 3))
    lift.direction = Direction.DOWN
    
    assertTrue(PassengerAlgorithms.isPointAlongTheWay(lift, 18))
    assertFalse(PassengerAlgorithms.isPointAlongTheWay(lift, 30))
  }

  @Test
  void bothPointsAlongTheWay() {
    Lift lift = new Lift(0)
    lift.position = 15
    lift.addPendingRequest(new Passenger("abc", 30))
    lift.direction = Direction.UP

    int cost = PassengerAlgorithms.transitionCost(lift, 20, 25)
    assertEquals(5, cost)
  }
  
  @Test
  void startAlongFinishNot() {
    Lift lift = new Lift(0)
    lift.position = 15
    lift.addPendingRequest(new Passenger("abc", 30))
    lift.direction = Direction.UP

    int cost = PassengerAlgorithms.transitionCost(lift, 20, 5)
    assertEquals(15+25, cost)
  }
  
  @Test
  void startAlongFinishNotWithPassengers() {
    Lift lift = new Lift(0)
    lift.position = 15
    lift.addPendingRequest(new Passenger("abc", 30))
    lift.direction = Direction.UP
    lift.addPassenger(new Passenger("sgzmd", 31))

    int cost = PassengerAlgorithms.transitionCost(lift, 20, 5)
    assertEquals(15+25+2, cost)
  }
  
  @Test
  void bothNotAlongPickupCloser() {
    Lift lift = new Lift(0)
    lift.position = 15
    lift.addPendingRequest(new Passenger("abc", 30))
    lift.direction = Direction.UP
    
    int cost = PassengerAlgorithms.transitionCost(lift, 10, 5)
    assertEquals(40, cost)
  }
  
  @Test
  void bothNotAlongDropoffCloser() {
    Lift lift = new Lift(0)
    lift.position = 15
    lift.addPendingRequest(new Passenger("abc", 30))
    lift.direction = Direction.UP
    
    int cost = PassengerAlgorithms.transitionCost(lift, 5, 10)
    assertEquals(45, cost)
  }
}
